package com.tv189.springbatchtest.restfuljob;


import org.springframework.batch.core.*;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: ResultfulController
 * @Description: TODO
 * @Author: 19202
 * @Date: 2025/6/4 21:42
 * @Version 1.0
 **/
@RestController
public class RestfulController {

    @Autowired
    public JobLauncher jobLauncher;

    @Autowired
    private Job job;

    @Autowired
    public JobExplorer jobExplorer;

    @GetMapping("/job/start")
    public ExitStatus start(String name) throws Exception{
        JobParameters jp = new JobParametersBuilder(jobExplorer)
                .getNextJobParameters(job)
                .addString("name", name)
                .toJobParameters();
        JobExecution run = jobLauncher.run(job, jp);
        return run.getExitStatus();
    }
}
